{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import jqdatasdk\n",
    "from jqdatasdk import get_all_securities\n",
    "import pandas as pd\n",
    "import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "auth success \n"
     ]
    }
   ],
   "source": [
    "with open(\"../data/auth_key.key\") as key:\n",
    "    auth_key = key.read().split(\",\")\n",
    "    jqdatasdk.auth(auth_key[0], auth_key[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock_code = jqdatasdk.get_all_securities(['stock'])\n",
    "stock_code['code']=stock_code.index\n",
    "stock_code.index=[x for x in range(len(stock_code))]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>display_name</th>\n",
       "      <th>name</th>\n",
       "      <th>start_date</th>\n",
       "      <th>end_date</th>\n",
       "      <th>type</th>\n",
       "      <th>code</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>平安银行</td>\n",
       "      <td>PAYH</td>\n",
       "      <td>1991-04-03</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000001.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>万科A</td>\n",
       "      <td>WKA</td>\n",
       "      <td>1991-01-29</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000002.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>国农科技</td>\n",
       "      <td>GNKJ</td>\n",
       "      <td>1990-12-01</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000004.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>世纪星源</td>\n",
       "      <td>SJXY</td>\n",
       "      <td>1990-12-10</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000005.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>深振业A</td>\n",
       "      <td>SZYA</td>\n",
       "      <td>1992-04-27</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000006.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>全新好</td>\n",
       "      <td>QXH</td>\n",
       "      <td>1992-04-13</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000007.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>神州高铁</td>\n",
       "      <td>SZGT</td>\n",
       "      <td>1992-05-07</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000008.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>中国宝安</td>\n",
       "      <td>ZGBA</td>\n",
       "      <td>1991-06-25</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000009.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>*ST美丽</td>\n",
       "      <td>*STML</td>\n",
       "      <td>1995-10-27</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000010.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>深物业A</td>\n",
       "      <td>SWYA</td>\n",
       "      <td>1992-03-30</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000011.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>南玻A</td>\n",
       "      <td>NBA</td>\n",
       "      <td>1992-02-28</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000012.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>沙河股份</td>\n",
       "      <td>SHGF</td>\n",
       "      <td>1992-06-02</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000014.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>深康佳A</td>\n",
       "      <td>SKJA</td>\n",
       "      <td>1992-03-27</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000016.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>深中华A</td>\n",
       "      <td>SZHA</td>\n",
       "      <td>1992-03-31</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000017.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>*ST神城</td>\n",
       "      <td>*STSC</td>\n",
       "      <td>1992-06-16</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000018.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>深粮控股</td>\n",
       "      <td>SLKG</td>\n",
       "      <td>1992-10-12</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000019.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>深华发A</td>\n",
       "      <td>SHFA</td>\n",
       "      <td>1992-04-28</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000020.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>深科技</td>\n",
       "      <td>SKJ</td>\n",
       "      <td>1994-02-02</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000021.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>深赤湾A</td>\n",
       "      <td>SCWA</td>\n",
       "      <td>1993-05-05</td>\n",
       "      <td>2018-12-25</td>\n",
       "      <td>stock</td>\n",
       "      <td>000022.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>深天地A</td>\n",
       "      <td>STDA</td>\n",
       "      <td>1993-04-29</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000023.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>招商地产</td>\n",
       "      <td>ZSDC</td>\n",
       "      <td>1993-06-07</td>\n",
       "      <td>2015-12-29</td>\n",
       "      <td>stock</td>\n",
       "      <td>000024.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>特力A</td>\n",
       "      <td>TLA</td>\n",
       "      <td>1993-06-21</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000025.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>飞亚达A</td>\n",
       "      <td>FYDA</td>\n",
       "      <td>1993-06-03</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000026.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>深圳能源</td>\n",
       "      <td>SZNY</td>\n",
       "      <td>1993-09-03</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000027.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>国药一致</td>\n",
       "      <td>GYYZ</td>\n",
       "      <td>1993-08-09</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000028.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>深深房A</td>\n",
       "      <td>SSFA</td>\n",
       "      <td>1993-09-15</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000029.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>富奥股份</td>\n",
       "      <td>FAGF</td>\n",
       "      <td>1993-09-29</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000030.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>大悦城</td>\n",
       "      <td>DYC</td>\n",
       "      <td>1993-10-08</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000031.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>深桑达A</td>\n",
       "      <td>SSDA</td>\n",
       "      <td>1993-10-28</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>000032.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>新都退</td>\n",
       "      <td>XDT</td>\n",
       "      <td>1994-01-03</td>\n",
       "      <td>2017-07-06</td>\n",
       "      <td>stock</td>\n",
       "      <td>000033.XSHE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3748</th>\n",
       "      <td>杭可科技</td>\n",
       "      <td>HKKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688006.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3749</th>\n",
       "      <td>光峰科技</td>\n",
       "      <td>GFKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688007.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3750</th>\n",
       "      <td>澜起科技</td>\n",
       "      <td>LQKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688008.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3751</th>\n",
       "      <td>中国通号</td>\n",
       "      <td>ZGTH</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688009.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3752</th>\n",
       "      <td>福光股份</td>\n",
       "      <td>FGGF</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688010.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3753</th>\n",
       "      <td>新光光电</td>\n",
       "      <td>XGGD</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688011.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3754</th>\n",
       "      <td>中微公司</td>\n",
       "      <td>ZWGS</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688012.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3755</th>\n",
       "      <td>交控科技</td>\n",
       "      <td>JKKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688015.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3756</th>\n",
       "      <td>心脉医疗</td>\n",
       "      <td>XMYL</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688016.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3757</th>\n",
       "      <td>乐鑫科技</td>\n",
       "      <td>LXKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688018.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3758</th>\n",
       "      <td>安集科技</td>\n",
       "      <td>AJKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688019.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3759</th>\n",
       "      <td>方邦股份</td>\n",
       "      <td>FBGF</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688020.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3760</th>\n",
       "      <td>瀚川智能</td>\n",
       "      <td>HCZN</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688022.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3761</th>\n",
       "      <td>沃尔德</td>\n",
       "      <td>WED</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688028.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3762</th>\n",
       "      <td>南微医学</td>\n",
       "      <td>NWYX</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688029.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3763</th>\n",
       "      <td>山石网科</td>\n",
       "      <td>SSWK</td>\n",
       "      <td>2019-09-30</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688030.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3764</th>\n",
       "      <td>天宜上佳</td>\n",
       "      <td>TYSJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688033.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3765</th>\n",
       "      <td>传音控股</td>\n",
       "      <td>CYKG</td>\n",
       "      <td>2019-09-30</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688036.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3766</th>\n",
       "      <td>航天宏图</td>\n",
       "      <td>HTHT</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688066.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3767</th>\n",
       "      <td>热景生物</td>\n",
       "      <td>RJSW</td>\n",
       "      <td>2019-09-30</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688068.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3768</th>\n",
       "      <td>虹软科技</td>\n",
       "      <td>HRKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688088.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3769</th>\n",
       "      <td>晶晨股份</td>\n",
       "      <td>JCGF</td>\n",
       "      <td>2019-08-08</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688099.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3770</th>\n",
       "      <td>天奈科技</td>\n",
       "      <td>TNKJ</td>\n",
       "      <td>2019-09-25</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688116.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3771</th>\n",
       "      <td>西部超导</td>\n",
       "      <td>XBCD</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688122.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3772</th>\n",
       "      <td>安博通</td>\n",
       "      <td>ABT</td>\n",
       "      <td>2019-09-06</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688168.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3773</th>\n",
       "      <td>柏楚电子</td>\n",
       "      <td>BCDZ</td>\n",
       "      <td>2019-08-08</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688188.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3774</th>\n",
       "      <td>微芯生物</td>\n",
       "      <td>WXSW</td>\n",
       "      <td>2019-08-12</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688321.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3775</th>\n",
       "      <td>铂力特</td>\n",
       "      <td>BLT</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688333.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3776</th>\n",
       "      <td>晶丰明源</td>\n",
       "      <td>JFMY</td>\n",
       "      <td>2019-10-14</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688368.XSHG</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3777</th>\n",
       "      <td>嘉元科技</td>\n",
       "      <td>JYKJ</td>\n",
       "      <td>2019-07-22</td>\n",
       "      <td>2200-01-01</td>\n",
       "      <td>stock</td>\n",
       "      <td>688388.XSHG</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>3778 rows × 6 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "     display_name   name start_date   end_date   type         code\n",
       "0            平安银行   PAYH 1991-04-03 2200-01-01  stock  000001.XSHE\n",
       "1             万科A    WKA 1991-01-29 2200-01-01  stock  000002.XSHE\n",
       "2            国农科技   GNKJ 1990-12-01 2200-01-01  stock  000004.XSHE\n",
       "3            世纪星源   SJXY 1990-12-10 2200-01-01  stock  000005.XSHE\n",
       "4            深振业A   SZYA 1992-04-27 2200-01-01  stock  000006.XSHE\n",
       "5             全新好    QXH 1992-04-13 2200-01-01  stock  000007.XSHE\n",
       "6            神州高铁   SZGT 1992-05-07 2200-01-01  stock  000008.XSHE\n",
       "7            中国宝安   ZGBA 1991-06-25 2200-01-01  stock  000009.XSHE\n",
       "8           *ST美丽  *STML 1995-10-27 2200-01-01  stock  000010.XSHE\n",
       "9            深物业A   SWYA 1992-03-30 2200-01-01  stock  000011.XSHE\n",
       "10            南玻A    NBA 1992-02-28 2200-01-01  stock  000012.XSHE\n",
       "11           沙河股份   SHGF 1992-06-02 2200-01-01  stock  000014.XSHE\n",
       "12           深康佳A   SKJA 1992-03-27 2200-01-01  stock  000016.XSHE\n",
       "13           深中华A   SZHA 1992-03-31 2200-01-01  stock  000017.XSHE\n",
       "14          *ST神城  *STSC 1992-06-16 2200-01-01  stock  000018.XSHE\n",
       "15           深粮控股   SLKG 1992-10-12 2200-01-01  stock  000019.XSHE\n",
       "16           深华发A   SHFA 1992-04-28 2200-01-01  stock  000020.XSHE\n",
       "17            深科技    SKJ 1994-02-02 2200-01-01  stock  000021.XSHE\n",
       "18           深赤湾A   SCWA 1993-05-05 2018-12-25  stock  000022.XSHE\n",
       "19           深天地A   STDA 1993-04-29 2200-01-01  stock  000023.XSHE\n",
       "20           招商地产   ZSDC 1993-06-07 2015-12-29  stock  000024.XSHE\n",
       "21            特力A    TLA 1993-06-21 2200-01-01  stock  000025.XSHE\n",
       "22           飞亚达A   FYDA 1993-06-03 2200-01-01  stock  000026.XSHE\n",
       "23           深圳能源   SZNY 1993-09-03 2200-01-01  stock  000027.XSHE\n",
       "24           国药一致   GYYZ 1993-08-09 2200-01-01  stock  000028.XSHE\n",
       "25           深深房A   SSFA 1993-09-15 2200-01-01  stock  000029.XSHE\n",
       "26           富奥股份   FAGF 1993-09-29 2200-01-01  stock  000030.XSHE\n",
       "27            大悦城    DYC 1993-10-08 2200-01-01  stock  000031.XSHE\n",
       "28           深桑达A   SSDA 1993-10-28 2200-01-01  stock  000032.XSHE\n",
       "29            新都退    XDT 1994-01-03 2017-07-06  stock  000033.XSHE\n",
       "...           ...    ...        ...        ...    ...          ...\n",
       "3748         杭可科技   HKKJ 2019-07-22 2200-01-01  stock  688006.XSHG\n",
       "3749         光峰科技   GFKJ 2019-07-22 2200-01-01  stock  688007.XSHG\n",
       "3750         澜起科技   LQKJ 2019-07-22 2200-01-01  stock  688008.XSHG\n",
       "3751         中国通号   ZGTH 2019-07-22 2200-01-01  stock  688009.XSHG\n",
       "3752         福光股份   FGGF 2019-07-22 2200-01-01  stock  688010.XSHG\n",
       "3753         新光光电   XGGD 2019-07-22 2200-01-01  stock  688011.XSHG\n",
       "3754         中微公司   ZWGS 2019-07-22 2200-01-01  stock  688012.XSHG\n",
       "3755         交控科技   JKKJ 2019-07-22 2200-01-01  stock  688015.XSHG\n",
       "3756         心脉医疗   XMYL 2019-07-22 2200-01-01  stock  688016.XSHG\n",
       "3757         乐鑫科技   LXKJ 2019-07-22 2200-01-01  stock  688018.XSHG\n",
       "3758         安集科技   AJKJ 2019-07-22 2200-01-01  stock  688019.XSHG\n",
       "3759         方邦股份   FBGF 2019-07-22 2200-01-01  stock  688020.XSHG\n",
       "3760         瀚川智能   HCZN 2019-07-22 2200-01-01  stock  688022.XSHG\n",
       "3761          沃尔德    WED 2019-07-22 2200-01-01  stock  688028.XSHG\n",
       "3762         南微医学   NWYX 2019-07-22 2200-01-01  stock  688029.XSHG\n",
       "3763         山石网科   SSWK 2019-09-30 2200-01-01  stock  688030.XSHG\n",
       "3764         天宜上佳   TYSJ 2019-07-22 2200-01-01  stock  688033.XSHG\n",
       "3765         传音控股   CYKG 2019-09-30 2200-01-01  stock  688036.XSHG\n",
       "3766         航天宏图   HTHT 2019-07-22 2200-01-01  stock  688066.XSHG\n",
       "3767         热景生物   RJSW 2019-09-30 2200-01-01  stock  688068.XSHG\n",
       "3768         虹软科技   HRKJ 2019-07-22 2200-01-01  stock  688088.XSHG\n",
       "3769         晶晨股份   JCGF 2019-08-08 2200-01-01  stock  688099.XSHG\n",
       "3770         天奈科技   TNKJ 2019-09-25 2200-01-01  stock  688116.XSHG\n",
       "3771         西部超导   XBCD 2019-07-22 2200-01-01  stock  688122.XSHG\n",
       "3772          安博通    ABT 2019-09-06 2200-01-01  stock  688168.XSHG\n",
       "3773         柏楚电子   BCDZ 2019-08-08 2200-01-01  stock  688188.XSHG\n",
       "3774         微芯生物   WXSW 2019-08-12 2200-01-01  stock  688321.XSHG\n",
       "3775          铂力特    BLT 2019-07-22 2200-01-01  stock  688333.XSHG\n",
       "3776         晶丰明源   JFMY 2019-10-14 2200-01-01  stock  688368.XSHG\n",
       "3777         嘉元科技   JYKJ 2019-07-22 2200-01-01  stock  688388.XSHG\n",
       "\n",
       "[3778 rows x 6 columns]"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 取得时间段\n",
    "start_date = datetime.datetime.now() + datetime.timedelta(days=-365)\n",
    "end_date = datetime.datetime.now()\n",
    "start_date=start_date.strftime(\"%Y-%m-%d\")\n",
    "end_date=end_date.strftime(\"%Y-%m-%d\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "stock_code['open']=0.0\n",
    "stock_code['close']=0.0\n",
    "stock_code['high']=0.0\n",
    "stock_code['low']=0.0\n",
    "stock_code['volume']=0.0\n",
    "stock_code['money']=0.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=jqdatasdk.get_price(\"002517.XSHE\", start_date=start_date, end_date=end_date,\n",
    "                                           frequency='minute',\n",
    "                                           fields=None,\n",
    "                                           skip_paused=False, fq='pre')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.to_csv('../data/Test.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "data=None\n",
    "num=1000\n",
    "for x in range(len(stock_code.head(num))):\n",
    "    code=stock_code.loc[x]['code']\n",
    "    display_name=stock_code.loc[x]['display_name']\n",
    "    temp = jqdatasdk.get_price(code, start_date=end_date, end_date=end_date,\n",
    "                                           frequency='daily',\n",
    "                                           fields=None,\n",
    "                                           skip_paused=False, fq='pre')\n",
    "    if type(data)==type(None):\n",
    "        data=temp\n",
    "    else:\n",
    "#         data=pd.merge(data,temp,on='datetime')\n",
    "        data=pd.concat([data,temp],axis=0)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock=stock_code.head(num)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "d:\\python36\\lib\\site-packages\\ipykernel_launcher.py:2: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \n"
     ]
    }
   ],
   "source": [
    "for column in data.columns:\n",
    "    stock[column]=data[column].values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1000, 12)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(1000, 6)"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "stock.to_csv('../data/NowDaysStock.csv',index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
